To integrate NicEdit in django Admin:
Download NicEdit from official website or register NicEdit script into project. Add NicEdit JavaScript file into project's static folder. Create an folder named "js" and place the NicEdit JavaScript file.Django Admin Configuration:
form.py:
from .models import Product
from django import forms
class ProductForm(forms.ModelForm):
class Meta:
model = Product # Specify your model
fields = '__all__' # Or list the fields you want to include
# Add a widget to the description field
description = forms.CharField(widget=forms.Textarea(attrs={'class': 'nic-edit','cols': 80}))
admin.py:
from django.contrib import admin
from .models import *
from .form import ProductForm
class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'description')
list_per_page=10
search_fields=['name','category__name']
form = ProductForm
class Media:
js = ('/static/js/nicEdit.js', '/static/js/script.js')
admin.site.register(Product, ProductAdmin)
script.js:
document.addEventListener("DOMContentLoaded", function() {
var textAreas = document.getElementsByClassName("nic-edit");
for (var i = 0; i < textAreas.length; i++) {
new nicEditor({ fullPanel: true }).panelInstance(textAreas[i]);
}
});
VIDEO GUIDE:
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article